<template>
  <div>
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
      <h1 class="edit-title">推荐人奖励</h1>
      <a-form-model-item ref="name" required>
        <template v-slot:label>
          <a-tooltip>
            <template slot="title">
              取最高条件奖励：可设置多个奖励条<br />
              件，最终取可达最高条件奖励一次 <br />
              满足条件即奖励：可设置多个奖励条 <br />
              件，达到即奖励，可奖励多次 <br />
              单条件循环奖励：仅支持设置一个奖<br />
              励条件，达到即奖励，可奖励多次<br />
              注：奖励方式复选，但计数对象仍为同一推荐人数
            </template>
            奖励方式<a-icon type="question-circle" style="margin-left: 4px" />
          </a-tooltip>
        </template>

        <a-checkbox v-model="highestType"> 取最高条件奖励 </a-checkbox>
        <div v-if="highestType">
          <div class="edit-box" v-for="(item, x) in satisfyList" :key="x">
            奖励条件{{ x + 1 }}
            <a-icon type="close-circle" theme="filled" class="edit-icon" @click="deleteSatisfy(x)" />
            <a-form layout="vertical" :label-col="{ span: 2 }" :wrapper-col="{ span: 18 }" style="margin-left: 20px">
              <a-form-item label="满" required style="display: flex; align-items: center"> <a-input-number v-model="item.awardReason" :min="1" :precision="0" />&nbsp;&nbsp;人奖励 </a-form-item>
              <a-form-item label="奖励" required class="reward">
                <a-checkbox :checked="item.integralType" @change="onChange(x)">
                  积分&nbsp;&nbsp;
                  <span v-if="item.integralType"> <a-input-number v-model="item.awardValue" :min="1" @change="changeInput(x)" :precision="0" /> &nbsp;&nbsp;分 </span>
                </a-checkbox>

                <div class="current"><a-checkbox v-model="item.couponType" @change="couponChange(x)"> 优惠券 </a-checkbox></div>
                <a-table :columns="columns" :data-source="item.prizeList" :pagination="false" :rowKey="record => record.id" v-show="item.couponType">
                  <span slot="coupon" slot-scope="text, record, index">
                    <a-input v-model="record.awardValue" :min="1" />
                  </span>
                  <span slot="sheetNum" slot-scope="text, record, index">
                    <a-input-number :max="100" v-model="record.awardTimes" :min="1" :precision="0" />
                  </span>
                  <span slot="action" slot-scope="text, record, index">
                    <a-icon type="delete" :style="{ fontSize: '16px', color: '#1890ff' }" @click="elSatisfy(x, index)" />
                  </span>
                </a-table>
                <div class="edit-coupon" v-show="item.couponType">
                  <a @click="satisfyCoupon(x)"><a-icon type="plus" /> 关联新的优惠券</a>
                </div>
              </a-form-item>
            </a-form>
          </div>

          <div style="margin-top: 10px">
            <a-button type="primary" @click="addSatisfy"> 添加奖励条件 </a-button>
            <span style="margin-left: 5px">最多支持10个条件</span>
          </div>
        </div>
        <div>
          <a-checkbox v-model="conditionType"> 满足条件即奖励 </a-checkbox>
          <div v-if="conditionType">
            <div class="edit-box" v-for="(item, x) in conditionList" :key="x">
              奖励条件{{ x + 1 }}
              <a-icon type="close-circle" theme="filled" class="edit-icon" @click="deleteClick(x)" />
              <a-form layout="vertical" :label-col="{ span: 2 }" :wrapper-col="{ span: 18 }" style="margin-left: 20px">
                <a-form-item label="满" required style="display: flex; align-items: center"> <a-input-number v-model="item.awardReason" :min="1" :precision="0" />&nbsp;&nbsp;人奖励 </a-form-item>
                <a-form-item label="奖励" required class="reward">
                  <a-checkbox @change="inteChange(x)" :checked="item.integralType">
                    积分&nbsp;&nbsp;
                    <span v-show="item.integralType"> <a-input-number v-model="item.awardValue" :min="1" @change="inteChangeInput(x)" :precision="0" />&nbsp;&nbsp;分 </span>
                  </a-checkbox>
                  <div class="current">
                    <a-checkbox @change="copChange(x)" v-model="item.couponType"> 优惠券 </a-checkbox>
                  </div>
                  <a-table :columns="columns" :data-source="item.prizeList" :pagination="false" :rowKey="record => record.id" v-show="item.couponType">
                    <span slot="coupon" slot-scope="text, record, index">
                      <a-input v-model="record.awardValue" :min="1" />
                    </span>
                    <span slot="sheetNum" slot-scope="text, record, index">
                      <a-input-number :max="100" v-model="record.awardTimes" :min="1" :precision="0" />
                    </span>
                    <span slot="action" slot-scope="text, record, index">
                      <a-icon type="delete" :style="{ fontSize: '16px', color: '#1890ff' }" @click="eliminate(x, index)" />
                    </span>
                  </a-table>
                  <div class="edit-coupon" v-show="item.couponType">
                    <a @click="addCoupon(x)"><a-icon type="plus" /> 关联新的优惠券</a>
                  </div>
                </a-form-item>
              </a-form>
            </div>
            <div style="margin-top: 10px">
              <a-button type="primary" @click="add"> 添加奖励条件 </a-button>
              <span style="margin-left: 5px">最多支持10个条件</span>
            </div>
          </div>
        </div>
        <div>
          <a-checkbox v-model="singleType"> 单条件循环奖励 </a-checkbox>
          <div class="edit-boxTwo" v-if="singleType">
            奖励条件
            <a-form layout="vertical" :label-col="{ span: 2 }" :wrapper-col="{ span: 18 }" style="margin-left: 20px">
              <a-form-item label="每满" required style="display: flex; align-items: center"> <a-input-number v-model="singleObj.awardReason" :min="1" :precision="0" />&nbsp;&nbsp;人奖励 </a-form-item>
              <a-form-item label="奖励" required class="reward">
                <a-checkbox :checked="singleObj.integralType" @change="singleChange">
                  积分&nbsp;&nbsp;
                  <span v-show="singleObj.integralType"> <a-input-number v-model="singleObj.awardValue" @change="limitInput" :min="1" :precision="0" />&nbsp;&nbsp;分 </span>
                </a-checkbox>
                <div class="current">
                  <a-checkbox v-model="singleObj.couponType" @change="individual"> 优惠券 </a-checkbox>
                </div>
                <a-table :columns="columns" :data-source="singleObj.prizeList" :pagination="false" :rowKey="record => record.id" v-show="singleObj.couponType">
                  <span slot="coupon" slot-scope="text, record, index">
                    <a-input v-model="record.awardValue" :min="1" />
                  </span>
                  <span slot="sheetNum" slot-scope="text, record, index">
                    <a-input-number v-model="record.awardTimes" :max="100" :min="1" :precision="0" />
                  </span>
                  <span slot="action" slot-scope="text, record, index">
                    <a-icon type="delete" :style="{ fontSize: '16px', color: '#1890ff' }" @click="delSingle(index)" />
                  </span>
                </a-table>
                <div class="edit-coupon" v-show="singleObj.couponType">
                  <a @click="addSingle()"><a-icon type="plus" /> 关联新的优惠券</a>
                </div>
              </a-form-item>

              <div>单人最多可享受奖励人数&nbsp;&nbsp;<a-input-number v-model="singleObj.maxCycleTimes" :min="1" :precision="0" /></div>
              <div>注：该人数为邀请总数</div>
            </a-form>
          </div>
          <div v-if="singleType">注：奖励方式复选，但计数对象仍为同一推荐人数</div>
        </div>
      </a-form-model-item>
      <a-form-model-item ref="name" label="活动限制">
        <div>
          <a-checkbox :checked="maxAwardType" @change="maxAwardChange"> 活动前&nbsp;&nbsp;<a-input-number v-model="maxAward" :min="1" :precision="0" />&nbsp;&nbsp;人可享受奖励 </a-checkbox>
        </div>
      </a-form-model-item>
      <h1 class="edit-title">被推荐人奖励</h1>
      <a-form-model-item ref="name" label="奖励">
        <div>
          <a-checkbox :checked="recommended.integralType" @change="recomChange">
            积分
            <span v-show="recommended.integralType"> <a-input-number v-model="recommended.awardValue" @change="reecomInput" :min="1" :precision="0" />&nbsp;&nbsp;分 </span>
          </a-checkbox>
          <div class="current">
            <a-checkbox v-model="recommended.couponType" @change="recomCoupon">优惠券</a-checkbox>
            <a-table :columns="columns" :data-source="recommended.prizeList" :pagination="false" :rowKey="record => record.id" v-show="recommended.couponType">
              <span slot="coupon" slot-scope="text, record">
                <a-input v-model="record.awardValue" :min="1" />
              </span>
              <span slot="sheetNum" slot-scope="text, record">
                <a-input-number v-model="record.awardTimes" :max="100" :min="1" :precision="0" />
              </span>
              <span slot="action" slot-scope="text, record, index">
                <a-icon type="delete" :style="{ fontSize: '16px', color: '#1890ff' }" @click="recomClick(index)" />
              </span>
            </a-table>
            <div class="edit-coupon" v-show="recommended.couponType">
              <a @click="addRecom()"><a-icon type="plus" /> 关联新的优惠券</a>
            </div>
          </div>
        </div>
      </a-form-model-item>
    </a-form-model>

    <!-- <h1>被推荐人奖励</h1> -->
  </div>
</template>
<script>
import { couponsDel } from '@/api/marketingCenter/passenger.js'
const columns = [
  {
    title: '优惠券',
    align: 'center',
    scopedSlots: { customRender: 'coupon' }
  },
  {
    title: '张数',
    align: 'center',
    scopedSlots: { customRender: 'sheetNum' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  data() {
    return {
      highestType: false,
      conditionType: false,
      singleType: false,
      maxAwardType: false,
      maxAward: null, // 活动限制人数
      columns,
      singleObj: {
        byCycle: '',
        awardBy: '1', // 推荐人奖励type
        ruleType: '3', //单个条件奖励type
        awardValue: '', // 积分
        maxCycleTimes: '', // 最多奖励人数
        integralType: false, // 积分复选框
        couponType: false, // 优惠券复选框
        awardReason: '', // 奖励人数
        prizeList: [], // 优惠券数据
        integralList: [] //积分数组
      },
      recommended: {
        awardBy: '2', // 推荐人奖励type
        awardValue: '', // 积分

        integralType: false, // 积分复选框
        couponType: false, // 优惠券复选框
        prizeList: [], // 优惠券数据
        integralList: [] //积分数组
      },
      number: '',
      labelCol: { span: 4 },
      wrapperCol: { span: 18 },
      form: {},
      rules: {},
      conditionList: [
        {
          awardBy: '1', // 推荐人奖励type
          ruleType: '2', //满足条件奖励type
          awardValue: '', // 积分
          integralType: false, // 积分复选框
          couponType: false, // 优惠券复选框
          awardReason: '', // 奖励人数
          prizeList: [], // 优惠券数据
          integralList: [], //积分数组
          byCondition: ''
        }
      ],
      copyList: [],
      satisfyList: [
        {
          awardBy: '1', // 推荐人奖励type
          ruleType: '1', //最高条件奖励type
          byMaxLvl: '',
          awardValue: '', // 积分
          integralType: false, // 积分
          couponType: false, // 优惠券
          awardReason: '', // 奖励人数
          prizeList: [], // 优惠券数组
          integralList: [] //积分数组
        }
      ],
      info: {
        awardBy: '1', // 推荐人奖励type
        ruleType: '1', //最高条件奖励type
        awardValue: '', // 积分
        integralType: false, // 积分复选框
        couponType: false, // 优惠券复选框
        awardReason: '', // 奖励人数
        prizeList: [], // 优惠券数据
        integralList: [] //积分数组
      }
    }
  },

  methods: {
    elId(id) {
      couponsDel(id).then(res => {
        if (res.code === 200) {
          this.$message.success('删除成功')
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    maxAwardChange(e) {
      this.maxAwardType = e.target.checked
    },
    reecomInput() {
      this.recommended.integralType = this.recommended.awardValue ? true : false
    },
    limitInput() {
      this.singleObj.integralType = this.singleObj.awardValue ? true : false
    },
    // 积分复选框
    onChange(idx) {
      this.satisfyList[idx].integralType = !this.satisfyList[idx].integralType
      this.$forceUpdate()
    },
    changeInput(index) {
      this.satisfyList[index].integralType = this.satisfyList[index].awardValue ? true : false
    },
    inteChangeInput(index) {
      this.conditionList[index].integralType = this.conditionList[index].awardValue ? true : false
    },
    // 优惠券复选框
    couponChange(index) {
      const obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }
      const newList = [...this.satisfyList]
      newList.map((item, i) => {
        if (i == index) {
          if (item.couponType) {
            item.prizeList.push(obj)
          } else {
            item.prizeList = []
          }
        }
      })
    },
    // 积分复选框
    inteChange(idx) {
      if (this.conditionList[idx]) this.conditionList[idx].integralType = !this.conditionList[idx].integralType
      this.$forceUpdate()
    },
    // 优惠券复选框
    copChange(index) {
      var obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }
      const newList = [...this.conditionList]
      newList.map((item, i) => {
        if (i == index) {
          if (item.couponType) {
            item.prizeList.push(obj)
          } else {
            item.prizeList = []
          }
        }
      })
    },
    //添加最高奖励条件
    addSatisfy() {
      if (this.satisfyList.length >= 10) {
        this.$message.warning('最多支持10个条件!')
        return
      }
      let info = {
        awardBy: '1', // 推荐人奖励type
        ruleType: '1', //最高条件奖励type
        awardValue: '', // 积分
        integralType: false, // 积分复选框
        couponType: false, // 优惠券复选框
        awardReason: '', // 奖励人数
        prizeList: [], // 优惠券数据
        integralList: [], //积分数组
        byMaxLvl: ''
      }

      this.satisfyList.push(info)
    },
    // 积分复选框
    singleChange() {
      this.singleObj.integralType = !this.singleObj.integralType
      this.$forceUpdate()
    },
    // 优惠券复选框
    individual() {
      let obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }
      if (this.singleObj.couponType) {
        this.singleObj.prizeList.push(obj)
      } else {
        this.singleObj.prizeList = []
      }
    },
    recomCoupon() {
      let obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }
      if (this.recommended.couponType) {
        this.recommended.prizeList.push(obj)
      } else {
        this.recommended.prizeList = []
      }
    },
    // 积分复选框
    recomChange() {
      this.recommended.integralType = !this.recommended.integralType
      this.$forceUpdate()
    },
    // 优惠券复选框
    mendedChange() {
      let obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: null
      }
      if (this.recommended.couponType) {
        this.recommended.prizeList.push(obj)
      } else {
        this.recommended.prizeList = []
      }
    },
    //添加满足奖励条件
    add() {
      if (this.conditionList.length >= 10) {
        this.$message.warning('最多支持10个条件!')
        return
      }
      let info = {
        awardBy: '1', // 推荐人奖励type
        ruleType: '2', //最高条件奖励type
        awardValue: '', // 积分
        integralType: false, // 积分复选框
        couponType: false, // 优惠券复选框
        awardReason: '', // 奖励人数
        prizeList: [], // 优惠券数据
        integralList: [], //积分数组
        byCondition: ''
      }
      this.conditionList.push(info)
    },
    //添加最高条件优惠券
    satisfyCoupon(idx) {
      let obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }
      let copanall = this.satisfyList[idx]
      if (copanall.couponType) {
        const newList = [...this.satisfyList]
        newList.map((item, i) => {
          if (i == idx) {
            item.prizeList.push(obj)
          }
        })
      } else {
        this.$message.warning('请勾选优惠券')
        return
      }
    },
    // 添加满足条件的优惠券
    addCoupon(index) {
      let obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }
      let copanall = this.conditionList[index]
      if (copanall.couponType) {
        const newList = [...this.conditionList]
        newList.map((item, i) => {
          if (i == index) {
            item.prizeList.push(obj)
          }
        })
      } else {
        this.$message.warning('请勾选优惠券')
        return
      }
    },
    //删除最高条件奖励
    deleteSatisfy(index) {
      console.log(this.satisfyList.length)
      if (this.satisfyList.length <= 1) {
        this.$message.warning('最少1个条件!')
        return
      }
      this.satisfyList.splice(index, 1)
    },
    // 删除满足条件奖励
    deleteClick(index) {
      if (this.conditionList.length <= 1) {
        this.$message.warning('最少1个条件!')
        return
      }
      this.conditionList.splice(index, 1)
    },
    //删除最高奖励条件优惠券
    elSatisfy(X, Y) {
      this.delSatisfy(X, Y)
    },
    delSatisfy(x, y) {
      const newList = [...this.satisfyList]
      newList.map((item, i) => {
        if (i == x) {
          item.prizeList.map((obj, j) => {
            if (y == j) {
              newList[x]['prizeList'].splice(j, 1)
              this.satisfyList = newList
            }
          })
        }
      })
    },
    // 删除满足条件优惠券
    eliminate(X, Y) {
      this.del(X, Y)
    },
    del(x, y) {
      const newList = [...this.conditionList]
      newList.map((item, i) => {
        if (i == x) {
          item.prizeList.map((obj, j) => {
            if (y == j) {
              newList[x]['prizeList'].splice(j, 1)
              this.conditionList = newList
            }
          })
        }
      })
    },
    // 添加单条件优惠券
    addSingle() {
      let obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }
      if (this.singleObj.couponType) {
        this.singleObj.prizeList.push(obj)
      } else {
        this.$message.warning('请勾选优惠券')
        return
      }
    },
    addRecom() {
      let obj = {
        awardType: '2',
        awardName: '奖励优惠券1张',
        awardValue: '',
        awardTimes: ''
      }

      if (this.recommended.couponType) {
        this.recommended.prizeList.push(obj)
      } else {
        this.$message.warning('请勾选优惠券')
        return
      }
    },
    // 删除单条件优惠券
    delSingle(index) {
      this.singleObj.prizeList.splice(index, 1)
    },
    recomClick(index) {
      this.recommended.prizeList.splice(index, 1)
    },
    tipFuntion(data) {
      var flag = true

      for (var i = 0; i < data.length; i++) {
        if (!data[i].awardReason) {
          this.$message.warning('请填写完整活动信息')
          flag = false
          return
        }
        if (!data[i].couponType && !data[i].integralType) {
          this.$message.warning('至少选择一种奖励方式')
          flag = false
        }
        if (data[i].integralType && !data[i].awardValue) {
          this.$message.warning('请填写完整活动信息')
          flag = false
        }
        if (data[i].couponType) {
          if (data[i].prizeList.length < 1) {
            this.$message.warning('请填写优惠券完整信息')
            return false
          }

          var valid = false
          for (var j = 0; j < data[i].prizeList.length; j++) {
            if (data[i].prizeList[j].awardValue && data[i].prizeList[j].awardTimes) {
              valid = true
            } else {
              valid = false
            }
            console.log(valid, 'valid')
            if (!valid) {
              this.$message.warning('请填写优惠券完整信息')
              flag = false
              return false
            }
          }
        }
        // if (data[i].maxCycleTimes != undefined) {
        //   console.log(data[i], 'data[i].maxCycleTimes')
        //   if (!data[i].maxCycleTimes) {
        //     this.$message.warning('请填写单人最多可享受奖励人数')
        //     flag = false
        //   }
        // }
      }
      return flag
    },

    // 提交
    onSubmit() {
      if (!this.highestType && !this.conditionType && !this.singleType) {
        this.$message.warning('请至少选择一个推荐人奖励方式')
        return
      }
      if (this.highestType) {
        if (this.satisfyList && this.satisfyList.length < 1) {
          this.$message.warning('请至少添加一个最高条件奖励')
          return
        }
      }
      if (this.conditionType) {
        if (this.conditionList && this.conditionList.length < 1) {
          this.$message.warning('请至少添加一个满足条件奖励')
          return
        }
      }
      if (this.recommended.awardValue) {
        if (!this.recommended.integralType) {
          this.$message.warning('请勾选被推荐人积分奖励')
          return
        }
      }
      if (this.recommended.integralType) {
        if (!this.recommended.awardValue) {
          this.$message.warning('请填写被推荐人积分奖励')
          return
        }
      }
      if (this.recommended.couponType) {
        let valid = true
        if (this.recommended.prizeList.length < 1) {
          this.$message.warning('请填写被推荐人优惠券完整信息')
          return false
        }

        for (var j = 0; j < this.recommended.prizeList.length; j++) {
          if (this.recommended.prizeList[j].awardValue && this.recommended.prizeList[j].awardTimes) {
            valid = true
          } else {
            valid = false
          }
          console.log(valid)
          if (!valid) {
            this.$message.warning('请填写被推荐人优惠券完整信息')
            return false
          }
        }
      }
      let newArr = []
      if (this.highestType) {
        this.satisfyList.forEach(item => {
          if (item.couponType || item.integralType || (item.couponType && item.integralType)) {
            newArr.push(item)
          }
        })
        let flag = this.tipFuntion(this.satisfyList)
        if (!flag) {
          return
        }
      }

      newArr.forEach(item => {
        item.integralList = []
        if (item.integralType && item.awardValue) {
          item.integralList.push({
            awardType: '1',
            awardName: `${item.awardValue}积分`,
            awardValue: item.awardValue
          })
        } else {
          item.integralList = []
        }
        item.byMaxLvl = item.awardReason
      })

      let newList = []
      if (this.conditionType) {
        this.conditionList.forEach(item => {
          if (item.couponType || item.integralType || (item.couponType && item.integralType)) {
            newList.push(item)
          }
        })
        let flag = this.tipFuntion(this.conditionList)
        if (!flag) {
          return
        }
      }
      newList.forEach(item => {
        item.integralList = []
        if (item.integralType && item.awardValue) {
          item.integralList.push({
            awardType: '1',
            awardName: `${item.awardValue}积分`,
            awardValue: item.awardValue
          })
        } else {
          item.integralList = []
        }
        item.byCondition = item.awardReason
      })

      if (this.singleType) {
        let singleList = [this.singleObj]
        console.log(this.singleObj, 'this.singleObj')
        let flag = this.tipFuntion(singleList)
        if (!flag) {
          return
        }
        if (!this.singleObj.maxCycleTimes) {
          this.$message.warning('请填写单人最多可享受奖励人数')
          return false
        }
      }
      let awardType = false
      if (this.maxAwardType && !this.maxAwar) {
        awardType = true
      }
      if (!awardType) {
        this.$message.warning('请填写活动限制')
        return false
      }

      if (this.recommended.integralType && this.recommended.awardValue) {
        this.recommended.integralList = []
        this.recommended.integralList.push({
          awardType: '1',
          awardName: `${this.recommended.awardValue}积分`,
          awardValue: this.recommended.awardValue
        })
      } else {
        this.recommended.integralList = []
      }

      console.log(newArr, 'newArr', '1')
      console.log(newList, 'newList', '2')
      console.log(this.singleObj, '3')
      console.log(this.recommended, '4')
      let arr = [...newArr, ...newList, this.recommended] //组成一个新数组
      if (this.singleType) {
        if (!this.singleObj.couponType && !this.singleObj.integralType) {
          return this.$message.error('警告信息')
        } else if (this.singleObj.couponType || this.singleObj.integralType) {
          arr.push(this.singleObj)
        }
        if (this.singleObj.integralType && this.singleObj.awardValue) {
          this.singleObj.integralList = []
          this.singleObj.integralList.push({
            awardType: '1',
            awardName: `${this.singleObj.awardValue}积分`,
            awardValue: this.singleObj.awardValue
          })
        } else {
          this.singleObj.integralList = []
        }
        this.singleObj.byCycle = this.singleObj.awardReason
      }

      let params = {
        maxAward: this.maxAward,
        arrList: arr
      }
      this.$emit('twoData', params)
      this.$emit('two', 2)
    },
    //回显
    setData(data) {
      data.rewardList.forEach(ele => {
        if (ele.integralList && ele.integralList.length > 0) {
          ele.awardValue = ele.integralList[0].awardValue
        }
      })
      let object = data.rewardList.filter(item => item.awardBy == 1 && item.ruleType == 3) // 单条件循环奖励

      if (object && object.length > 0) {
        this.singleObj = object && object.length > 0 ? object[0] : {}
        this.singleType = object && object.length > 0 ? true : false
        this.singleObj.integralType = object && object[0].integralList.length > 0 ? true : false
        this.singleObj.couponType = object && object[0].prizeList.length > 0 ? true : false
        console.log(this.singleObj, 'this.singleObj')
      }
      let Info = data.rewardList.filter(item => item.awardBy == 2) // 被推荐人奖励
      this.recommended = Info[0]
      this.recommended.integralType = Info && Info[0].integralList.length > 0 ? true : false
      this.recommended.couponType = Info && Info[0].prizeList.length > 0 ? true : false

      this.maxAward = data.maxAward
      this.maxAwardType = data.maxAward ? true : false
      this.satisfyList = data.rewardList.filter(item => item.awardBy == 1 && item.ruleType == 1)
      this.highestType = this.satisfyList && this.satisfyList.length > 0 ? true : false
      if (this.satisfyList && this.satisfyList.length > 0) {
        this.satisfyList.forEach(item => {
          item.couponType = item.prizeList.length > 0 ? true : false
          item.integralType = item.integralList.length > 0 ? true : false
        })
      }
      this.conditionList = data.rewardList.filter(item => item.awardBy == 1 && item.ruleType == 2)
      if (this.conditionList && this.conditionList.length > 0) {
        this.conditionList.forEach(item => {
          item.couponType = item.prizeList.length > 0 ? true : false
          item.integralType = item.integralList.length > 0 ? true : false
        })
      }
      this.conditionType = this.conditionList && this.conditionList.length > 0 ? true : false
    }
  }
}
</script>
<style  scoped lang="less">
.edit-box {
  // width: 450px;
  min-height: 240px;
  padding: 16px;
  background: #eee;
  position: relative;
  margin-top: 5px;
  .edit-icon {
    position: absolute;
    right: 10px;
    top: 20px;
    font-size: 16px;
    cursor: pointer;
  }
}
.edit-boxTwo {
  // width: 450px;
  // min-height: 510px;
  padding: 16px;
  background: #eee;
}
.reward {
  display: flex;
  padding-bottom: 0px !important;
}
/deep/ .reward .ant-form-item-control-wrapper {
  flex: 1;
}
/deep/ .reward .ant-form-item-label {
  margin-top: 5px;
}
.current {
  margin-top: 8px;
  margin-bottom: 10px;
}
/deep/ .ant-table-thead > tr > th {
  background: transparent;
  border-bottom: none;
}
.edit-coupon {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}
.edit-title {
  margin-top: 50px;
  margin-left: 100px;
  font-size: 20px;
}
/deep/ .ant-table-placeholder {
  max-height: 145px;
}
/deep/ .ant-input-number-handler-wrap {
  display: none !important;
}
</style>